import 'package:flutter/material.dart';
import 'package:huajianshe_app/common/res.dart';

class OverlappedWidget extends StatelessWidget {

  final List<Widget>? widgets;
  final int widgetW;
  final int widgetH;
  final int overlap;

  const OverlappedWidget(this.widgets, this.widgetW, this.widgetH, this.overlap, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (widgets?.isNotEmpty == true) {
      int size = widgets!.length;
      int width = widgetW * size + (size - 1) * overlap;
      int height = widgetH;
      List<Widget> result = [];
      for (int i = 0; i < widgets!.length; i++) {
        result.add(Positioned(child: widgets![i], left: (i * widgetW + i * overlap).toDouble(),));
      }
      return SizedBox(width: width.toDouble(), height: height.toDouble(), child: Stack(children: [...result],));
    }
    return W(0);
  }
}